import { ModalForm, ProFormItem, ProFormText, ProFormTreeSelect, ProFormTextArea } from "@ant-design/pro-components";
import { message } from "antd";
import { dataSubjectPublish } from '@/api/sharing/dataSubject'
import { dataCatalogTree } from "@/api/sharing/dataCatalog";

const PublishModalForm = ({ onFinish, ...props }) => {
  const handleSubmit = (values) => {
    return dataSubjectPublish(values).then((res) => {
      if (res.code !== 200) return false
      onFinish()
      message.success('发布成功')
      return true
    })
  }
  return <ModalForm
    width={'400px'}
    title={'数据资源发布'}
    modalProps={{ destroyOnClose: true }}
    onFinish={handleSubmit}
    grid={true}
    {...props}
  >

    <ProFormItem name='id' hidden />

    <ProFormText
      name="themeName"
      label="数据资源名称"
      placeholder="请输入数据资源名称"
      disabled
      rules={[{ required: true, message: '数据资源名称不能为空' }]}
    />
    <ProFormText
      name="themeSign"
      label="数据资源标识"
      placeholder="请输入数据资源标识"
      disabled
      rules={[{ required: true, message: '数据资源标识不能为空' }]}
    />
    <ProFormText
      name="publishName"
      label="发布机构名称"
      placeholder="请输入机构名称"
      rules={[{ required: true, message: '机构名称不能为空' }]}
    />
    <ProFormTreeSelect
      name="catalogId"
      label="数据资源目录"
      placeholder="数据资源目录"
      rules={[{ required: true, message: '请选择数据资源目录' }]}
      fieldProps={{
        fieldNames: {
          label: 'catalogName',
          value: 'id',
          children: 'childTreeList',
        }
      }}
      request={() => {
        return dataCatalogTree().then((res) => {
          return res.result || []
        })
      }}
    />
    <ProFormTextArea
      rows={4}
      name="themeRemark"
      label="数据资源描述"
      placeholder="请输入内容"
    />
  </ModalForm>;
}

export default PublishModalForm;